package com.cowin.inf.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.cowin.base.result.Result;
import com.cowin.base.result.ResultGenerator;
import com.cowin.sys.model.VehicleImpress;
import com.cowin.sys.service.TmVhcVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright (C), 1998-2019, 奇瑞信息
 *
 * @author : 于超
 * @Date: 2019/12/4 13:16
 * @Description: 车型配置解析表
 */
@Slf4j
@RestController
@RequestMapping("inf/bdc")
@Api(value = "InfBdcController", description = "涂装车间控制器", tags = "EmosController", consumes = "application/json")
public class InfBdcController {
    @Resource
    private TmVhcVehicleService tmVhcVehicleService;

    @Value("${interface.uri.mes.impressUrl}")
    private String impressUrl;

    @Value("${spring.profiles.active}")
    private String env;

    @GetMapping("/interpret/vehicle/job")
    @ApiOperation(value = "BDC 车型配置解析下发", notes = "BDC 车型配置解析下发")
    public Result interpretVehicleJob() {
        if (!"dev".equals(env)) {
            List<VehicleImpress> settingDict = tmVhcVehicleService.getSettingDict();
            log.info("BDC车辆特征解析表接口下发  {}", JSON.toJSONString(settingDict));
            try {
                String data = HttpUtil.post(impressUrl, JSON.toJSONString(settingDict));
                log.info("BDC返回数据 {}", data);
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        } else {
            log.info("测试环境 BDC车辆特征解析表接口下发 接口停止");
        }
        return ResultGenerator.genSuccessResult("调用成功");
    }
}
